﻿using System;
using System.Collections.Generic;
using System.Text;
using Zove.Runtime;
using VIJAY.MATH;

namespace WPF3DTutorial {
    public class EquationGroup {
        public List<string> Equations {
            get;
            set;
        }

        public List<string> Elements {
            get;
            set;
        }

        public EquationGroup(string[] eg) {
            this.Elements = new List<string>();
            this.Equations = new List<string>();

            this.Equations.AddRange(eg);
        }

        public override int GetHashCode() {
            return base.GetHashCode();
        }

        public EquationGroup(List<string> eg)
            : this(eg.ToArray()) {
        }

        public override bool Equals(object obj) {
            if (!obj.GetType().Equals(typeof(EquationGroup))) {
                return false;
            }

            EquationGroup eg = (EquationGroup)obj;

            foreach (string e in eg.Equations) {
                if (!this.Equations.Contains(e)) {
                    return false;
                }
            }

            return true;
        }

        public double[] Evaluate()
        {
            List<string> s = new List<string>();
            Dictionary<string, string> rpl = new Dictionary<string, string>();

            foreach (string e in this.Equations)
            {
                string m = e + "=0";
                s.Add(m);
            }

            NonLinear.SetSystem(s.ToArray());
            double[] r = NonLinear.QuasiNewton();

            return r;
        }
    }
}
